package com.eddie.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * University就是Composite,可以管理College
 *
 * @author Eddie
 * @date 2022/08/01 11:28
 **/
public class University extends OrganizationComponent {

    List<OrganizationComponent> organizationComponents = new ArrayList<>();

    public University(String name, String des) {
        super(name, des);
    }

    /**
     * 重写add方法
     */
    @Override
    protected void add(OrganizationComponent component) {
        organizationComponents.add(component);
    }

    /**
     * 重写remove方法
     *
     * @param component
     */
    @Override
    protected void remove(OrganizationComponent component) {
        organizationComponents.remove(component);
    }

    /**
     * print就是输出University包含的学院
     */
    @Override
    protected void print() {
        System.out.println("---------------------" + getName() + "---------------------");
        //遍历List打印
        organizationComponents.forEach(OrganizationComponent::print);
    }
}
